<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>通知添加框</title>
<link rel="stylesheet"
	href="../plugins/umeditor/themes/default/css/umeditor.css" />
<script type="text/javascript"
	src="../plugins/umeditor/third-party/jquery.min.js"></script>
<script type="text/javascript"
	src="../plugins/umeditor/umeditor.config.js"></script>
<script type="text/javascript" src="../plugins/umeditor/umeditor.min.js"></script>
<script type="text/javascript"
	src="../plugins/umeditor/lang/zh-cn/zh-cn.js"></script>

<link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="../css/main.css" />
</head>
<body>
	<div>
		<fieldset class="layui-elem-field layui-field-title"
			style="margin-top: 10px;">
			<legend>通知发布</legend>
		</fieldset>
		<form class="layui-form">
			<div class="layui-form-item">
				<label class="layui-form-label">标题</label>
				<div class="layui-input-block">
					<input type="text" name="title" lay-verify="title" id="title"
						autocomplete="off" placeholder="请输入标题" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">内容 </label>
				<div class="layui-input-block">
					<textarea id="editor"></textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="demo3">确定</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="../plugins/layui/layui.js"></script>
	<script type="text/javascript"
		src="http://localhost:8080/Bank/js/sockjs-0.3.min.js"></script>
	<script type="text/javascript" src="../js/websocket.js"></script>
	<script type="text/javascript">
		layui.config({
			base : '../plugins/layui/modules/'
		});
		layui.use([ 'form' ], function() {
			var form = layui.form(),
				$ = layui.jquery,
				layer = layui.layer;
	
			//使用百度的编辑器
			var um = UM.getEditor('editor', {
				initialFrameHeight : 180,
				initialFrameWidth : 550,
				maximumWords : 1000,
				autoHeightEnabled : false
			});
	
			var username = readCookie("userName");
	
			//自定义验证规则
			form.verify({
				title : function(value) {
					if (value.length < 1) {
						return '标题不能为空';
					}
				}
			});
	
			//监听提交
			form.on('submit(demo3)', function(data) {
				var info = data.field,
					e = new Date,
					time = e.getFullYear() + "-" + e.getMonth() + 1 + "-" + e.getDate() + "  " + e.getHours() + ":" + e.getMinutes(),
					json = {
						"name" : username,
						"title" : info.title,
						"content" : um.getContent(),
						"time" : time
					};
				$('#title').val('');
				um.setContent("");
				layui.send(JSON.stringify(json));
				layer.msg('发布通知成功');
				return false;
			});
	
			function readCookie(name) {
				var cookieValue = "";
				var search = name + "=";
				if (document.cookie.length > 0) {
					offset = document.cookie.indexOf(search);
					if (offset != -1) {
						offset += search.length;
						end = document.cookie.indexOf(";", offset);
						if (end == -1)
							end = document.cookie.length;
						cookieValue = (document.cookie.substring(offset, end))
					}
				}
				return cookieValue;
			}
		});
	</script>
</body>

</html>